/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.unal.bioingenium.kbmed.knowledge.mapping.vo;

import co.edu.unal.bioingenium.kbmed.knowledge.ontology.vo.Concept;
import co.edu.unal.bioingenium.kbmed.util.math.UtilMath;

/**
 *
 * @author  Alejandro Riveros Cruz
 */
public class ConceptIdentified implements Comparable<ConceptIdentified> {

    private double score;
    private double[] detailedScore;
    private Concept concept;

    /**
     * @param:
     * @return:
     */
    public ConceptIdentified() {
        concept = new Concept();
        score = 0;
    }

    /**
     *
     * @param conceptId 
     * @param score 
     */
    public ConceptIdentified(String conceptId, double score) {
        concept = new Concept(conceptId);
        this.score = score;
    }

    /**
     *
     * @return
     */
    public String getCategory() {
        return concept.getCategory();
    }

    /**
     *
     * @param category
     */
    public void setCategory(String category) {
        concept.setCategory(category);
    }

    /**
     *
     * @return
     */
    public String getConceptId() {
        return concept.getConceptId();
    }

    /**
     *
     * @param conceptId
     */
    public void setConceptId(String conceptId) {
        concept.setConceptId(conceptId);
    }

    /**
     *
     * @return
     */
    public String getDescription() {
        return concept.getDescription();
    }

    /**
     *
     * @param description
     */
    public void setDescription(String description) {
        concept.setDescription(description);
    }

    /**
     *
     * @return
     */
    public short getNumTokens() {
        return concept.getNumTokens();
    }

    /**
     *
     * @param numTokens
     */
    public void setNumTokens(short numTokens) {
        concept.setNumTokens(numTokens);
    }

    /**
     * @param:
     * @return:
     */
    public double getScore() {
        return score;
    }

    /**
     * @param:
     * @return:
     */
    public void setScore(double score) {
        if (score == Double.NaN || score == Double.POSITIVE_INFINITY || score == Double.NEGATIVE_INFINITY) {
            throw  new NumberFormatException();
        }
        this.score = score;
    }

    /**
     * @param:
     * @return:
     */
    public void setDetailedScore(double[][] scores, int[] maximunIndex) {
        detailedScore = new double[scores[0].length];
        for (int i = 0; i < maximunIndex.length; i++) {
            if (maximunIndex[i] >= 0) {
                detailedScore[maximunIndex[i]] = scores[i][maximunIndex[i]];
            }
        }
    }

    /**
     * 
     * @param weigths
     */
    public void weitghScore(double[] weigths) {
        double weigth = 0;
        if (detailedScore.length == weigths.length) {
            for (int i = 0; i < detailedScore.length; i++) {
                weigth += UtilMath.indicator(detailedScore[i]) * weigths[i];
            }
        }
        score = score * weigth;
    }

    /**
     * 
     * @param weigth
     */
    public void weitghScore(double weigth) {
        score = score * weigth;
    }

    /**
     * 
     * @return
     */
    public double[] getDetailedScore() {
        return detailedScore;
    }

    @Override
    public int compareTo(ConceptIdentified o) {
        if (this.score > o.getScore()) {
            return -1;
        } else {
            return 1;
        }
    }
}
